package com.customization.workflow;

import com.alibaba.fastjson.JSON;
import com.engine.core.cfg.annotation.ServiceDynamicProxy;
import com.engine.core.cfg.annotation.ServiceMethodDynamicProxy;
import com.engine.core.impl.aop.AbstractServiceProxy;

import com.engine.workflow.entity.operationMenu.OperationMenuEntity;

import com.engine.workflow.service.impl.workflowPath.OperationMenuServiceImpl;
import com.engine.workflow.service.workflowPath.OperationMenuService;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;


import java.util.List;
import java.util.Map;

@ServiceDynamicProxy(target = OperationMenuServiceImpl.class,desc = "测试")
public class GetNodeMenuProxy extends AbstractServiceProxy implements OperationMenuService {


    @Override
    @ServiceMethodDynamicProxy(desc = "代理节点菜单新增催办菜单。。")
    public Map<String, Object> getCurrentNodeMenuSetData(Map<String, Object> map) {
       new BaseBean().writeLog("getCurrentNodeMenuSetData is in ");
        //调用被代理类方法
        Map<String, Object> result = (Map<String, Object>)executeMethod( map);
        int workflowid = Util.getIntValue(Util.null2String(map.get("wfid")));
        new BaseBean().writeLog("增加菜单时:"+workflowid);
        int nodeid = Util.getIntValue(Util.null2String(map.get("nodeid")));
       //String sql="select *  from workflow_iscb where wfid='"+workflowid+"' and nodeid='"+nodeid+"'";
//        String sql="select *  from workflow_iscb where wfid='?' and nodeid='?'";
//        RecordSet rs=new RecordSet();
//        rs.executeQuery(sql,workflowid,nodeid);
        String isuse="0";
        String diyname="";
//        if(rs.next()){
//            isuse=rs.getString("isuse");
//            diyname=rs.getString("diyname");
//        }
        List data=(List) result.get("opratorSetDatas");
        OperationMenuEntity entity=new OperationMenuEntity();

        entity.setId(1001);
        entity.setOrderId(2);
        entity.setMenuType(-1001);
        entity.setDefaultName("是否短信提醒");
        entity.setCustomName(diyname);
        entity.setFeedBackControl("测试");
        entity.setFeedBackControlName("测试1");
//        Map<String ,Object> leavelMap=new HashMap();
//        leavelMap.put()
//
//        entity.setCom();
        //是否启用
        entity.setStartUsing(Integer.parseInt(isuse));

        data.add(entity);
        result.put("opratorSetDatas",data);

        new BaseBean().writeLog(""+result);
        return result;
    }

    @Override
    public Map<String, Object> getForwardMenu(int i, int i1) {
        return null;
    }

    @Override
    public Map<String, Object> getRejectMenu(int i, int i1) {
        return null;
    }

    @Override
    public Map<String, Object> getSelectRange(int i, int i1, String s) {
        return null;
    }

    @Override
    public Map<String, Object> saveForwardMenu(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> saveRejectMenu(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> saveSelectRange(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> saveTakingMenu(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getNewFlowMenu(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> saveNewFlow(Map<String, Object> map) {
        return null;
    }

    @ServiceMethodDynamicProxy(desc = "代理节点菜单新增催办菜单保存功能。。")
    @Override
    public Map<String, Object> saveOperationMenu(Map<String, Object> map) {
        BaseBean baseBean= new BaseBean();
        RecordSet rs=new RecordSet();
        baseBean.writeLog("saveOperationMenu is in ");
        //调用被代理类方法
        Map<String, Object> result = (Map<String, Object>)executeMethod( map);
        int workflowid = Util.getIntValue(Util.null2String(map.get("workflowid")));
        int nodeid = Util.getIntValue(Util.null2String(map.get("nodeid")));
        String data = Util.null2String(map.get("data"));
        List<OperationMenuEntity>  list= JSON.parseArray(data, OperationMenuEntity.class);
        for(int i=0;i<list.size();i++){
            OperationMenuEntity entity=list.get(i);
            int did=entity.getId();
            int isuse=entity.getStartUsing();
            String diyname=entity.getCustomName();
            baseBean.writeLog(entity.getId()+"----");
            //保存数据操作
            if(did==1001){
               // String sql="select *  from workflow_iscb where wfid="+workflowid+" and nodeid="+nodeid;
                String sql="select *  from workflow_iscb where wfid='?' and nodeid='?'";

                rs.executeQuery(sql,workflowid,nodeid);
                if(rs.next()){
                   // String sqlu="update workflow_iscb set isuse='"+isuse+"',diyName='"+diyname+"' where wfid="+workflowid+" and nodeid="+nodeid;
                    String sqlu="update workflow_iscb set isuse='?',diyName='?' where wfid='?' and nodeid='?'";
                    rs.executeUpdate(sqlu,isuse,diyname,workflowid);
                }else {
                   // String sqli="insert into workflow_iscb (wfid,nodeid,isuse,diyName) values ('"+workflowid+"','"+nodeid+"','"+isuse+"','"+diyname+"')";
                    String sqli="insert into workflow_iscb (wfid,nodeid,isuse,diyName) values ('?','?','?','?')";
                    rs.executeUpdate(sqli,workflowid,nodeid,isuse,diyname);
                }
            }
        }

       // List opratorSetDatas=(List) map.get("data");
       // baseBean.writeLog("opratorSetDatas size: "+opratorSetDatas.size());

        return result;
    }

    @Override
    public Map<String, Object> getNewMessage(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> saveNewMessage(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getBackNameMenu(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> saveBackNameMenu(Map<String, Object> map) {
        return null;
    }
    @Override
    public Map<String, Object> saveCustomOperation(Map<String, Object> map) {
        return null;
    }

    @Override
    public Map<String, Object> getCustOptFormField(Map<String, Object> map) {
        return null;
    }

    @Override
   public  Map<String, Object> saveChuanyue(Map<String, Object> var1){ return null;};
    @Override
    public  Map<String, Object> getChuanyueSet(Map<String, Object> var1){ return null;}
    @Override
    public Map<String, Object> getMenuOrderSet(Map<String, Object> var1){ return null;}
    @Override
    public  Map<String, Object> saveMenuOrderSet(Map<String, Object> var1){ return null;}
    @Override
    public Map<String, Object> getCustomOperationSetDetail(Map<String, Object> var1){ return null;}
    @Override
    public Map<String, Object> saveCustomOperationSetDetail(Map<String, Object> var1){ return null;}
    @Override
    public Map<String, Object> getCustomOperationSetRigthDetail(Map<String, Object> var1){ return null;}
    @Override
    public Map<String, Object> getCustomOperationSetListDetail(Map<String, Object> var1){ return null;}



}
